package com.wedimob.slideshare.task.network;

import java.io.IOException;
import java.net.URL;

import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.wedimob.slideshare.Reader;

public class DefaultReader implements Reader {

	private static String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21";

	@Override
	public Document get(URL url, int timeout) {
		try {
			return Jsoup.connect(url.toString()).timeout(timeout * 1000)
					.userAgent(USER_AGENT).get();
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	@Override
	public Response getRaw(URL url, int timeout) {
		try {
			return Jsoup.connect(url.toString()).timeout(timeout * 1000)
					.userAgent(USER_AGENT).ignoreContentType(true).execute();
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}
